//
//  MLAScanResultVC.m
//  MagicLampApp
//
//  Created by Zheng on 2019/4/23.
//  Copyright © 2019 zheng.magic.lamp.app. All rights reserved.
//

#import "MLAScanResultVC.h"
#import "MLAScanResultStatusVC.h"
#import "MLAPayCodeVC.h"
#import "MLAPayCodeVC.h"

@interface MLAScanResultVC ()

@property (nonatomic, strong) UITextField *inputTxf;
@property (nonatomic, copy) NSString *orderId;


@end

@implementation MLAScanResultVC {
    dispatch_source_t timer;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self configTitle:@"输入金额"];
    
    UILabel *titleLbl = [[UILabel alloc] init];
    titleLbl.font = CX_GetNormalFont(12);
    titleLbl.textColor = CX_GetColorHex(0x999999, 1);
    titleLbl.text = @"输入金额";
    [self.view addSubview:titleLbl];
    [titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.top.equalTo(self.titleView.mas_bottom).offset(20);
    }];
    
    _inputTxf = [[UITextField alloc] init];
    _inputTxf.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
    _inputTxf.placeholder = @"输入金额";
    _inputTxf.font = CX_GetNormalFont(15);
    UILabel *leftLbl = [[UILabel alloc] init];
    leftLbl.frame = CGRectMake(0, 0, 30, 30);
    leftLbl.font = CX_GetNormalFont(17);
    leftLbl.text = @"¥";
    _inputTxf.leftView = leftLbl;
    _inputTxf.leftViewMode = UITextFieldViewModeAlways;
    [self.view addSubview:_inputTxf];
    [_inputTxf mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.right.offset(-15);
        make.top.equalTo(titleLbl.mas_bottom).offset(15);
        make.height.offset(30);
    }];
    
    UIButton *enterBtn =  [self getCommitButtonWithTitle:@"确认收款"];
    [enterBtn addTarget:self action:@selector(enterBtnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:enterBtn];
    [enterBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.right.offset(-15);
        make.height.offset(40);
        make.top.equalTo(self.inputTxf.mas_bottom).offset(200);
    }];

}



- (void)enterBtnAction {
    
    if (_inputTxf.text.length == 0) {
        [MLAHudManage showMessage:@"请输入金额"];
        return;
    }
    
    if (_isPayCode) {
        MLAPayCodeVC *payVC = [[MLAPayCodeVC alloc] init];
        payVC.moneyStr = _inputTxf.text;
        [self.navigationController pushViewController:payVC animated:YES];
        
    } else {
        NSDictionary *param = @{@"acc_no":_code,
                                @"amount":[NSString stringWithFormat:@"%ld",(NSInteger)(_inputTxf.text.doubleValue*100)]
                                };
        [MLAHttpManage postHostType:MLAHttpHostType_Diancan api:kShopPayCoverPay params:param success:^(id  _Nonnull response, NSString * _Nonnull msg) {
            
            MLAScanResultStatusVC *srsVC = [[MLAScanResultStatusVC alloc] init];
            [self.navigationController pushViewController:srsVC animated:YES];
            
            if ([response[@"status"] integerValue] == 2) {
                [MLAHudManage showMessage:@"支付成功"];
                
            } else {
                [MLAHudManage showMessage:@"支付失败,请重新扫码收款"];
            }
            
        } failure:^{
            
        }];

    }
    

}


@end
